<html>

  <head>
    <title>To Do List Today !</title>
  </head>

  <body>
    <div class="main">
      <!--输入框-->
      <div style="color: #408ab0;text-align: center;">^-^ 今日任务 ^-^</div>
      <div class="row">
        <input class="input" type="text" id="inputtext" placeholder="请输入 TO DO 内容" onkeyup="keyup(event)"/>
        <input type="button" name="bt" id="button1" value="任务新增" onclick="handleClick(event)" />
        <input type="button" name="bt" id="button2" value="清空" onclick="empty(event)" />
      </div>
      <div id="todogroup">
        <!--这里面 todo项-->
      </div>
      <div id="xx" onmouseenter="enter('xx')" onmouseleave="leave('xx')">
      <hr style="border:1px dotted pink">
      </div>
      <div>      
        <input id="checkall" type = "checkbox" onclick="selectAll()" >全部完成！</button>
      </div>
    <!--操作的footer-->  
    </div>
  </body>
  <script lang="javacript">

    var intCnt = 0;

    function init(){
        document.getElementById("button2").onclick = empty;
    }
    function empty(e){
        console.log('delteall');
        console.log(e);
        document.getElementById("todogroup").innerHTML="";
    }
    function keyup(e){
      console.log(e);

      if(e.keyCode == 13){
        handleClick(e);
      }
    }
    
    function handleClick(e){

        console.log('handleClick');
        console.log(e);
        var temp = getValue();  
        var div = document.createElement('div');
        document.getElementById("todogroup").innerHTML += "<div class='item' div id='todo"
            + intCnt + "'><input type='checkbox' name='todocheck'><div class='item-value'>"
            + temp + "</div><button class='item-del' type='button' onclick='deleteByIndex("
            + intCnt + ")'>删除</button></div>";
        document.getElementById("inputtext").value = "";
        intCnt++;
    }

    function getValue(){
      var temp = document.getElementById("inputtext");
      console.log(temp.value);
        
        return temp.value;
    }

    function deleteByIndex(index){
      document.getElementById("todo" + index).remove();
    }

    function enter(id){
      document.getElementById(id).style='background-color:#3e3e3e'
    }

    function leave(id){
      document.getElementById(id).style='background-color:#FFFFFF'
    }

    function selectAll(){
      var check = document.getElementById("checkall");
      console.log(check.checked);
      var cnt = document.getElementsByName("todocheck");
      if(check.checked==true){
        for(var i = 0; i < cnt.length; i++){
          cnt[i].checked = true;
        }
      } else {
        for(var i = 0; i < cnt.length; i++){
          cnt[i].checked = false;
        }
      }
    }


    init();
  </script>
  <style>
    body {
      display: flex;
      justify-content: center;
      align-items: center;
    }

    .main {
      background-color: #dde8f4;
      padding: 8px;
      border: 3px solid rgb(178, 202, 225);
      border-radius: 8px;
    }

    .row {
      display: flex;
      justify-content: center;
      align-items: center;
      min-height: 5vh;
    }

    .item{
      margin: 6px;
      padding: 3px;
      border-radius: 3px;
      display: flex;
      align-items: center;
    }

    .item:hover{
      background-color: #f5e2ca;
      transform: scale(1.2);
    }

    .item-value{
      flex-grow: 1;
      color: #6c67a7;
    }

    .item-del{
      color: rgb(136, 130, 201);
      background-color: #f6c0b4;
      border: 0px;
      opacity: 0;
    }

    .item:hover .item-del{
      opacity: 1;
    }

    .input{
      padding: 5px;
      outline: none;
      border: 2px solid #b1afaf;
      outline:none;
    }

    .input:focus{
      box-shadow: 0px 0px 10px #d5e6e0;
      border: 2px solid #d5e6e0;
      outline:none;
    }
    
    #button1 {
      margin: 2px;
      border-radius: 2px;
      background-color: #e5ccd2;
      border: 2px solid #dbbfc6;
      outline:none;
    }

    #button2 {
      margin: 2px;
      border-radius: 2px;
      background-color: #e5ccd2;
      border: 2px solid #dbbfc6;
      outline:none;
    }
  </style>

</html>